Commit dcb878f7 authored by michael.simon's avatar michael.simon
Browse files

access service password by serviceShortName

parent a873fed2
...@@ -25,6 +25,7 @@ import edu.kit.scc.webreg.exc.NotAuthorizedException; ...@@ -25,6 +25,7 @@ import edu.kit.scc.webreg.exc.NotAuthorizedException;
import edu.kit.scc.webreg.exc.RegisterException; import edu.kit.scc.webreg.exc.RegisterException;
import edu.kit.scc.webreg.sec.AuthorizationBean; import edu.kit.scc.webreg.sec.AuthorizationBean;
import edu.kit.scc.webreg.service.RegistryService; import edu.kit.scc.webreg.service.RegistryService;
import edu.kit.scc.webreg.service.ServiceService;
import edu.kit.scc.webreg.service.UserService; import edu.kit.scc.webreg.service.UserService;
import edu.kit.scc.webreg.service.reg.RegisterUserService; import edu.kit.scc.webreg.service.reg.RegisterUserService;
import edu.kit.scc.webreg.service.reg.RegisterUserWorkflow; import edu.kit.scc.webreg.service.reg.RegisterUserWorkflow;
...@@ -41,6 +42,9 @@ public class SetServicePasswordBean implements Serializable { ...@@ -41,6 +42,9 @@ public class SetServicePasswordBean implements Serializable {
@Inject @Inject
private RegistryService registryService; private RegistryService registryService;
@Inject
private ServiceService serviceService;
@Inject @Inject
private AuthorizationBean authBean; private AuthorizationBean authBean;
...@@ -61,19 +65,32 @@ public class SetServicePasswordBean implements Serializable { ...@@ -61,19 +65,32 @@ public class SetServicePasswordBean implements Serializable {
private UserEntity userEntity; private UserEntity userEntity;
private Long id; private Long id;
private String serviceShortName;
private String password1, password2; private String password1, password2;
private Long initializedId; private Boolean initialized = false;
public void preRenderView(ComponentSystemEvent ev) { public void preRenderView(ComponentSystemEvent ev) {
if (id != initializedId) { if (! initialized) {
userEntity = userService.findById(sessionManager.getUserId());
if (id != null) {
registryEntity = registryService.findById(id); registryEntity = registryService.findById(id);
if (registryEntity == null) if (registryEntity == null)
throw new IllegalArgumentException("Service Registry not found"); throw new IllegalArgumentException("Service Registry not found");
userEntity = userService.findById(sessionManager.getUserId());
serviceEntity = registryEntity.getService(); serviceEntity = registryEntity.getService();
}
else if (serviceShortName != null) {
serviceEntity = serviceService.findByShortName(serviceShortName);
if (serviceEntity == null)
throw new IllegalArgumentException("Service not found");
registryEntity = registryService.findByServiceAndUserAndStatus(serviceEntity, userEntity, RegistryStatus.ACTIVE);
}
if (! registryEntity.getUser().getId().equals(userEntity.getId())) if (! registryEntity.getUser().getId().equals(userEntity.getId()))
throw new NotAuthorizedException("Not authorized to view this item"); throw new NotAuthorizedException("Not authorized to view this item");
...@@ -84,7 +101,7 @@ public class SetServicePasswordBean implements Serializable { ...@@ -84,7 +101,7 @@ public class SetServicePasswordBean implements Serializable {
password1 = null; password1 = null;
password2 = null; password2 = null;
initializedId = id; initialized = true;
} }
} }
...@@ -172,4 +189,12 @@ public class SetServicePasswordBean implements Serializable { ...@@ -172,4 +189,12 @@ public class SetServicePasswordBean implements Serializable {
public void setPassword2(String password2) { public void setPassword2(String password2) {
this.password2 = password2; this.password2 = password2;
} }
public String getServiceShortName() {
return serviceShortName;
}
public void setServiceShortName(String serviceShortName) {
this.serviceShortName = serviceShortName;
}
} }
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<f:view> <f:view>
<f:metadata> <f:metadata>
<f:viewParam name="registryId" value="#{setServicePasswordBean.id}"/> <f:viewParam name="registryId" value="#{setServicePasswordBean.id}"/>
<f:viewParam name="ssn" value="#{setServicePasswordBean.serviceShortName}"/>
<f:event type="javax.faces.event.PreRenderViewEvent" <f:event type="javax.faces.event.PreRenderViewEvent"
listener="#{setServicePasswordBean.preRenderView}" /> listener="#{setServicePasswordBean.preRenderView}" />
</f:metadata> </f:metadata>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment