Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Max Mecklin
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 10c72b2d
authored
Jun 01, 2014
by
Antti Tönkyrä
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code-based authentication for netauth
1 parent
5b977bee
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
0 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/NetworkAssociationBean.java
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/NetworkAssociationBeanLocal.java
code/MoyaWeb/src/fi/codecrew/moya/rest/NetworkAssociationRestView.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/NetworkAssociationBean.java
View file @
10c72b2
...
@@ -19,6 +19,7 @@ import fi.codecrew.moya.model.EventUser;
...
@@ -19,6 +19,7 @@ import fi.codecrew.moya.model.EventUser;
import
fi.codecrew.moya.model.GroupMembership
;
import
fi.codecrew.moya.model.GroupMembership
;
import
fi.codecrew.moya.model.NetworkAssociation
;
import
fi.codecrew.moya.model.NetworkAssociation
;
import
fi.codecrew.moya.model.Place
;
import
fi.codecrew.moya.model.Place
;
import
fi.codecrew.moya.model.PrintedCard
;
import
fi.codecrew.moya.model.Role
;
import
fi.codecrew.moya.model.Role
;
/**
/**
...
@@ -44,6 +45,9 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
...
@@ -44,6 +45,9 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
private
EventBean
eventBean
;
private
EventBean
eventBean
;
@EJB
@EJB
private
CardTemplateBean
cardBean
;
@EJB
private
PermissionBean
permissionBean
;
private
PermissionBean
permissionBean
;
public
NetworkAssociationBean
()
{}
public
NetworkAssociationBean
()
{}
...
@@ -83,6 +87,21 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
...
@@ -83,6 +87,21 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
if
(
authUser
==
null
)
if
(
authUser
==
null
)
throw
new
Exception
(
"INVALID_USER_OR_PASSWORD"
);
throw
new
Exception
(
"INVALID_USER_OR_PASSWORD"
);
return
tryAssociateInternal
(
authUser
,
ip
,
mac
,
code
,
codeRequired
);
}
@Override
@RolesAllowed
(
NetworkAssociationPermission
.
S_CAN_ADMINISTER_ASSOCIATIONS
)
public
NetworkAssociation
tryAssociate
(
String
usercode
,
String
ip
,
String
mac
,
String
code
,
Boolean
codeRequired
)
throws
Exception
{
EventUser
authUser
=
userBean
.
getUser
(
usercode
);
if
(
authUser
==
null
)
throw
new
Exception
(
"INVALID_USERCODE"
);
return
tryAssociateInternal
(
authUser
,
ip
,
mac
,
code
,
codeRequired
);
}
private
NetworkAssociation
tryAssociateInternal
(
EventUser
authUser
,
String
ip
,
String
mac
,
String
code
,
boolean
codeRequired
)
throws
Exception
{
NetworkAssociation
association
;
NetworkAssociation
association
;
HashSet
<
IAppPermission
>
userPerms
=
buildPermsFor
(
authUser
);
HashSet
<
IAppPermission
>
userPerms
=
buildPermsFor
(
authUser
);
...
...
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/NetworkAssociationBeanLocal.java
View file @
10c72b2
...
@@ -25,4 +25,7 @@ public interface NetworkAssociationBeanLocal {
...
@@ -25,4 +25,7 @@ public interface NetworkAssociationBeanLocal {
NetworkAssociation
getActiveAssociationByIP
(
String
ipAddress
);
NetworkAssociation
getActiveAssociationByIP
(
String
ipAddress
);
NetworkAssociation
tryAssociate
(
String
usercode
,
String
ip
,
String
mac
,
String
code
,
Boolean
codeRequired
)
throws
Exception
;
}
}
code/MoyaWeb/src/fi/codecrew/moya/rest/NetworkAssociationRestView.java
View file @
10c72b2
...
@@ -60,6 +60,37 @@ public class NetworkAssociationRestView {
...
@@ -60,6 +60,37 @@ public class NetworkAssociationRestView {
return
resp
;
return
resp
;
}
}
@POST
@Path
(
"/codeauth"
)
@Produces
({
MediaType
.
APPLICATION_JSON
})
public
NetworkAssociationResponseRoot
codeAuth
(
@FormParam
(
"usercode"
)
String
usercode
,
@FormParam
(
"ip"
)
String
ip
,
@FormParam
(
"mac"
)
String
mac
,
@FormParam
(
"code"
)
String
code
,
@FormParam
(
"coderequired"
)
Boolean
codeRequired
)
{
NetworkAssociationResponseRoot
resp
=
new
NetworkAssociationResponseRoot
();
try
{
NetworkAssociation
na
=
networkAssociationBean
.
tryAssociate
(
usercode
,
ip
,
mac
,
code
,
codeRequired
);
if
(
na
.
getStatus
().
equals
(
NetworkAssociationStatus
.
ACTIVE
))
resp
.
getAdditions
().
add
(
new
NetworkAssociationActionPojo
(
na
.
getIP
(),
na
.
getMAC
()));
else
resp
.
getPendings
().
add
(
new
NetworkAssociationActionPojo
(
na
.
getIP
(),
na
.
getMAC
()));
}
catch
(
Exception
e
)
{
resp
.
getResult
().
setResultCode
(
0
);
if
(
e
.
getMessage
()
!=
null
&&
e
.
getMessage
()
!=
""
)
{
resp
.
getResult
().
setMessage
(
e
.
getMessage
());
}
else
{
resp
.
getResult
().
setMessage
(
"UNKNOWN_ERROR"
);
}
}
return
resp
;
}
@GET
@GET
@Path
(
"/get_association_infos"
)
@Path
(
"/get_association_infos"
)
@Produces
({
MediaType
.
APPLICATION_JSON
})
@Produces
({
MediaType
.
APPLICATION_JSON
})
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment