mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-09 06:33:29 +02:00
added ScmState
This commit is contained in:
91
scm-webapp/src/main/java/sonia/scm/RepositoryType.java
Normal file
91
scm-webapp/src/main/java/sonia/scm/RepositoryType.java
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class RepositoryType
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public RepositoryType() {}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @param displayName
|
||||
*/
|
||||
public RepositoryType(String name, String displayName)
|
||||
{
|
||||
this.name = name;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getDisplayName()
|
||||
{
|
||||
return displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param displayName
|
||||
*/
|
||||
public void setDisplayName(String displayName)
|
||||
{
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String displayName;
|
||||
|
||||
/** Field description */
|
||||
private String name;
|
||||
}
|
||||
113
scm-webapp/src/main/java/sonia/scm/ScmState.java
Normal file
113
scm-webapp/src/main/java/sonia/scm/ScmState.java
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@XmlRootElement(name = "state")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class ScmState
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public ScmState() {}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public RepositoryType[] getRepositoryTypes()
|
||||
{
|
||||
return repositoryTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getUsername()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isSuccess()
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryTypes
|
||||
*/
|
||||
public void setRepositoryTypes(RepositoryType[] repositoryTypes)
|
||||
{
|
||||
this.repositoryTypes = repositoryTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param success
|
||||
*/
|
||||
public void setSuccess(boolean success)
|
||||
{
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param username
|
||||
*/
|
||||
public void setUsername(String username)
|
||||
{
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "repositoryTypes")
|
||||
private RepositoryType[] repositoryTypes;
|
||||
|
||||
/** Field description */
|
||||
private boolean success = true;
|
||||
|
||||
/** Field description */
|
||||
private String username;
|
||||
}
|
||||
@@ -7,6 +7,11 @@
|
||||
|
||||
package sonia.scm.api.rest.resources;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.RepositoryType;
|
||||
import sonia.scm.ScmState;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.inject.Singleton;
|
||||
@@ -18,6 +23,7 @@ import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
@@ -43,27 +49,25 @@ public class AuthenticationResource
|
||||
* @return
|
||||
*/
|
||||
@POST
|
||||
public Response authenticate(@Context HttpServletRequest request,
|
||||
@FormParam("username") String username,
|
||||
@FormParam("password") String password)
|
||||
public ScmState getState(@Context HttpServletRequest request,
|
||||
@FormParam("username") String username,
|
||||
@FormParam("password") String password)
|
||||
{
|
||||
Response response = null;
|
||||
ScmState state = null;
|
||||
|
||||
if ("hans".equals(username) && "hans123".equals(password))
|
||||
{
|
||||
request.getSession(true).setAttribute("auth", Boolean.TRUE);
|
||||
response = Response.ok().build();
|
||||
request.getSession(true).setAttribute("auth", username);
|
||||
state = getState(username);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = Response.status(Response.Status.UNAUTHORIZED).build();
|
||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
return response;
|
||||
return state;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -73,21 +77,44 @@ public class AuthenticationResource
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
public Response isAuthenticated(@Context HttpServletRequest request)
|
||||
public ScmState getState(@Context HttpServletRequest request)
|
||||
{
|
||||
Response response = null;
|
||||
ScmState state = null;
|
||||
String username = (String) request.getSession(true).getAttribute("auth");
|
||||
|
||||
if (request.getSession(true).getAttribute("auth") != null)
|
||||
if (username != null)
|
||||
{
|
||||
System.out.println( "authenticated" );
|
||||
|
||||
response = Response.ok().build();
|
||||
state = getState(username);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = Response.status(Response.Status.UNAUTHORIZED).build();
|
||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
return response;
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param username
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private ScmState getState(String username)
|
||||
{
|
||||
ScmState state = new ScmState();
|
||||
|
||||
state.setUsername(username);
|
||||
|
||||
RepositoryType[] types = new RepositoryType[] {
|
||||
new RepositoryType("hg", "Mercurial"),
|
||||
new RepositoryType("svn", "Subversion"),
|
||||
new RepositoryType("git", "Git") };
|
||||
|
||||
state.setRepositoryTypes(types);
|
||||
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,13 @@
|
||||
|
||||
var debug = true;
|
||||
|
||||
var repositoryTypes = [ ['Mercurial', 'hg'], ['Subversion','svn'], ['Git','git'] ];
|
||||
var state = null;
|
||||
|
||||
var repositoryTypeStore = new Ext.data.ArrayStore({
|
||||
/*var repositoryTypes = [ ['Mercurial', 'hg'], ['Subversion','svn'], ['Git','git'] ];*/
|
||||
|
||||
var repositoryTypeStore = new Ext.data.JsonStore({
|
||||
id: 1,
|
||||
fields: [ 'name', 'type' ],
|
||||
data: repositoryTypes
|
||||
fields: [ 'displayName', 'name' ]
|
||||
});
|
||||
|
||||
var restUrl = "api/rest/";
|
||||
@@ -116,7 +116,10 @@ Ext.onReady(function(){
|
||||
Ext.Ajax.request({
|
||||
url: restUrl + 'authentication.json',
|
||||
method: 'GET',
|
||||
success: function(){
|
||||
success: function(response){
|
||||
state = Ext.decode(response.responseText);
|
||||
console.debug( state );
|
||||
repositoryTypeStore.loadData(state.repositoryTypes);
|
||||
createMainMenu();
|
||||
},
|
||||
failure: function(){
|
||||
|
||||
@@ -18,7 +18,8 @@ Sonia.group.EditForm = new Ext.extend(Sonia.rest.EditForm, {
|
||||
fieldLabel:'Name',
|
||||
name:'name',
|
||||
anchor: '100%',
|
||||
allowBlank: false
|
||||
allowBlank: false,
|
||||
readOnly: this.data != null
|
||||
},{
|
||||
fieldLabel: 'Members',
|
||||
xtype: 'fieldset',
|
||||
|
||||
@@ -9,14 +9,17 @@ Sonia.repository.EditForm = Ext.extend(Sonia.rest.EditForm, {
|
||||
|
||||
initComponent: function(){
|
||||
|
||||
var update = this.data != null;
|
||||
|
||||
var config = {
|
||||
title: 'Edit Repository',
|
||||
items:[
|
||||
{fieldLabel: 'Name', name: 'name', allowBlank: false},
|
||||
{fieldLabel: 'Name', name: 'name', readOnly: update, allowBlank: false},
|
||||
{
|
||||
fieldLabel: 'Type',
|
||||
name: 'type',
|
||||
xtype: 'combo',
|
||||
readOnly: update,
|
||||
hiddenName : 'type',
|
||||
typeAhead: true,
|
||||
triggerAction: 'all',
|
||||
@@ -24,8 +27,8 @@ Sonia.repository.EditForm = Ext.extend(Sonia.rest.EditForm, {
|
||||
mode: 'local',
|
||||
editable: false,
|
||||
store: repositoryTypeStore,
|
||||
valueField: 'type',
|
||||
displayField: 'name',
|
||||
valueField: 'name',
|
||||
displayField: 'displayName',
|
||||
allowBlank: false
|
||||
},
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ Sonia.rest.EditForm = Ext.extend(Ext.form.FormPanel, {
|
||||
|
||||
title: 'Edit REST',
|
||||
data: null,
|
||||
|
||||
|
||||
initComponent: function(){
|
||||
|
||||
var config = {
|
||||
|
||||
Reference in New Issue
Block a user