List of usage examples for org.springframework.security.oauth2.provider.approval Approval getExpiresAt
@JsonSerialize(using = JsonDateSerializer.class, include = JsonSerialize.Inclusion.NON_NULL) public Date getExpiresAt()
From source file:oauth2.authentication.approvals.ApprovalServiceImpl.java
static Approval fromEntity(oauth2.entities.Approval entity) { return new Approval(entity.getUserId(), entity.getClientId(), entity.getScope(), toDate(entity.getExpiresAt()), entity.getStatus(), toDate(entity.getLastUpdateAt())); }
From source file:oauth2.authentication.approvals.ApprovalServiceImpl.java
static oauth2.entities.Approval toEntity(Approval approval) { oauth2.entities.Approval entity = new oauth2.entities.Approval(); entity.setUserId(approval.getUserId()); entity.setClientId(approval.getClientId()); entity.setScope(approval.getScope()); entity.setStatus(approval.getStatus()); entity.setExpiresAt(toInstant(approval.getExpiresAt())); entity.setLastUpdateAt(toInstant(approval.getLastUpdatedAt())); return entity; }
From source file:org.meruvian.yama.web.security.oauth.DefaultOauthApplicationApprovalService.java
@Override @Transactional/*from ww w . j a v a 2 s. c om*/ public boolean addApprovals(Collection<Approval> approvals) { for (Approval approval : approvals) { OauthApplicationApproval a = getApprovalByUserAndClientAndScope(approval.getUserId(), approval.getClientId(), approval.getScope()); if (a != null) { a.setStatus(approval.getStatus() == null ? ApprovalStatus.APPROVED : ApprovalStatus.valueOf(approval.getStatus().name())); a.setExpiresAt(approval.getExpiresAt()); } else { a = new OauthApplicationApproval(); { Application application = new Application(); application.setId(approval.getClientId()); a.setApplication(application); } a.setExpiresAt(approval.getExpiresAt()); a.setScope(approval.getScope()); a.setStatus(approval.getStatus() == null ? ApprovalStatus.APPROVED : ApprovalStatus.valueOf(approval.getStatus().name())); } approvalRepository.save(a); } return true; }
From source file:com.cedac.security.oauth2.provider.approval.MongoApprovalStore.java
@Override public boolean addApprovals(final Collection<Approval> approvals) { LOG.debug(APPROVAL, "Adding approvals: {}", approvals); boolean success = true; for (Approval approval : approvals) { DBObject query = new BasicDBObject(userIdFieldName, approval.getUserId()) .append(clientIdFieldName, approval.getClientId()).append(scopeFieldName, approval.getScope()); DBObject obj = getApprovalsCollection().findOne(query); if (obj == null) { obj = new BasicDBObject(userIdFieldName, approval.getUserId()) .append(clientIdFieldName, approval.getClientId()) .append(scopeFieldName, approval.getScope()); }//from ww w .j a va2s . c o m obj.put(statusFieldName, approval.getStatus().name()); obj.put(expiresAtFieldName, approval.getExpiresAt()); obj.put(lastModifiedAtFieldName, approval.getLastUpdatedAt()); LOG.trace(APPROVAL, "Saving approval {}", obj); WriteResult result = getApprovalsCollection().save(obj, writeConcern); LOG.trace(APPROVAL, "Approval save result is {}", result); success = success && result.getN() == 1; } return success; }
From source file:org.springframework.security.oauth2.provider.approval.ApprovalStoreUserApprovalHandler.java
public AuthorizationRequest checkForPreApproval(AuthorizationRequest authorizationRequest, Authentication userAuthentication) { String clientId = authorizationRequest.getClientId(); Collection<String> requestedScopes = authorizationRequest.getScope(); Set<String> approvedScopes = new HashSet<String>(); Set<String> validUserApprovedScopes = new HashSet<String>(); if (clientDetailsService != null) { try {/*w ww.j a v a2 s . c o m*/ ClientDetails client = clientDetailsService.loadClientByClientId(clientId); for (String scope : requestedScopes) { if (client.isAutoApprove(scope) || client.isAutoApprove("all")) { approvedScopes.add(scope); } } if (approvedScopes.containsAll(requestedScopes)) { authorizationRequest.setApproved(true); return authorizationRequest; } } catch (ClientRegistrationException e) { logger.warn("Client registration problem prevent autoapproval check for client=" + clientId); } } if (logger.isDebugEnabled()) { StringBuilder builder = new StringBuilder("Looking up user approved authorizations for "); builder.append("client_id=" + clientId); builder.append(" and username=" + userAuthentication.getName()); logger.debug(builder.toString()); } // Find the stored approvals for that user and client Collection<Approval> userApprovals = approvalStore.getApprovals(userAuthentication.getName(), clientId); // Look at the scopes and see if they have expired Date today = new Date(); for (Approval approval : userApprovals) { if (approval.getExpiresAt().after(today)) { validUserApprovedScopes.add(approval.getScope()); if (approval.getStatus() == ApprovalStatus.APPROVED) { approvedScopes.add(approval.getScope()); } } } if (logger.isDebugEnabled()) { logger.debug("Valid user approved/denied scopes are " + validUserApprovedScopes); } // If the requested scopes have already been acted upon by the user, // this request is approved if (validUserApprovedScopes.containsAll(requestedScopes)) { approvedScopes.retainAll(requestedScopes); // Set only the scopes that have been approved by the user authorizationRequest.setScope(approvedScopes); authorizationRequest.setApproved(true); } return authorizationRequest; }
From source file:org.springframework.security.oauth2.provider.approval.JdbcApprovalStore.java
private boolean updateApproval(final String sql, final Approval approval) { logger.debug(String.format("refreshing approval: [%s]", approval)); int refreshed = jdbcTemplate.update(sql, new PreparedStatementSetter() { @Override//from www. jav a 2 s .c om public void setValues(PreparedStatement ps) throws SQLException { ps.setTimestamp(1, new Timestamp(approval.getExpiresAt().getTime())); ps.setString(2, (approval.getStatus() == null ? APPROVED : approval.getStatus()).toString()); ps.setTimestamp(3, new Timestamp(approval.getLastUpdatedAt().getTime())); ps.setString(4, approval.getUserId()); ps.setString(5, approval.getClientId()); ps.setString(6, approval.getScope()); } }); if (refreshed != 1) { return false; } return true; }