Skip to content

Commit

Permalink
Extend SecurityUtils (flowable#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaHinex committed Jan 28, 2018
1 parent eb290b4 commit f163a25
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
6 changes: 6 additions & 0 deletions modules/flowable-ui-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.proper.enterprise.platform</groupId>
<artifactId>pep-auth-api</artifactId>
<version>0.4.0-SNAPSHOT</version>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
*/
package org.flowable.app.security;

import com.proper.enterprise.platform.api.auth.service.UserService;
import com.proper.enterprise.platform.core.PEPApplicationContext;
import org.flowable.app.model.common.RemoteUser;
import org.flowable.idm.api.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.ArrayList;
import java.util.Collection;

/**
* Utility class for Spring Security.
* Utility class to integrate PEP authc and authz into Flowable.
*/
public final class SecurityUtils {

Expand All @@ -27,11 +31,15 @@ public final class SecurityUtils {
private SecurityUtils() {
}

private static UserService getUserService() {
return PEPApplicationContext.getBean(UserService.class);
}

/**
* Get the login of the current user.
*/
public static String getCurrentUserId() {
User user = getCurrentUserObject();
com.proper.enterprise.platform.api.auth.model.User user = getUserService().getCurrentUser();
if (user != null) {
return user.getId();
}
Expand All @@ -55,25 +63,26 @@ public static User getCurrentUserObject() {
}

public static FlowableAppUser getCurrentFlowableAppUser() {
FlowableAppUser user = null;
SecurityContext securityContext = SecurityContextHolder.getContext();
if (securityContext != null && securityContext.getAuthentication() != null) {
Object principal = securityContext.getAuthentication().getPrincipal();
if (principal instanceof FlowableAppUser) {
user = (FlowableAppUser) principal;
}
}
return user;
com.proper.enterprise.platform.api.auth.model.User curUser = getUserService().getCurrentUser();
User user = new RemoteUser();
user.setId(curUser.getId());
user.setPassword(curUser.getPassword());
user.setEmail(curUser.getEmail());
user.setLastName(curUser.getUsername());

Collection<? extends GrantedAuthority> collection = new ArrayList<>();
return new FlowableAppUser(user, user.getId(), collection);
}

public static boolean currentUserHasCapability(String capability) {
FlowableAppUser user = getCurrentFlowableAppUser();
for (GrantedAuthority grantedAuthority : user.getAuthorities()) {
if (capability.equals(grantedAuthority.getAuthority())) {
return true;
}
}
return false;
// FlowableAppUser user = getCurrentFlowableAppUser();
// for (GrantedAuthority grantedAuthority : user.getAuthorities()) {
// if (capability.equals(grantedAuthority.getAuthority())) {
// return true;
// }
// }
// return false;
return true;
}

public static void assumeUser(User user) {
Expand Down

0 comments on commit f163a25

Please sign in to comment.