Advertisement
Guest User

Untitled

a guest
Jun 15th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.13 KB | None | 0 0
  1. package com.github.sobolewskikamil.soa.service.soap;
  2.  
  3. import com.github.sobolewskikamil.soa.persistence.api.model.CategoryType;
  4. import com.github.sobolewskikamil.soa.persistence.api.model.ElementType;
  5. import com.github.sobolewskikamil.soa.persistence.api.remote.CategoryTypeDao;
  6. import com.github.sobolewskikamil.soa.persistence.api.remote.OwnerDao;
  7.  
  8. import javax.annotation.Resource;
  9. import javax.ejb.EJB;
  10. import javax.jws.WebService;
  11. import javax.xml.ws.BindingProvider;
  12. import javax.xml.ws.WebServiceContext;
  13. import javax.xml.ws.handler.MessageContext;
  14. import java.util.List;
  15. import java.util.Map;
  16.  
  17. @WebService(endpointInterface = "com.github.sobolewskikamil.soa.service.soap.CategoryTypeDao")
  18. public class CategoryTypeDaoImpl implements com.github.sobolewskikamil.soa.service.soap.CategoryTypeDao {
  19.     @EJB(mappedName = "java:global/soa-project-persistence-server/CategoryTypeDao!com.github.sobolewskikamil.soa.persistence.api.remote.CategoryTypeDao")
  20.     private CategoryTypeDao categoryTypeDao;
  21.     @EJB(mappedName = "java:global/soa-project-persistence-server/OwnerDao!com.github.sobolewskikamil.soa.persistence.api.remote.OwnerDao")
  22.     private OwnerDao ownerDao;
  23.     @Resource
  24.     private WebServiceContext webServiceContext;
  25.  
  26.     @Override
  27.     public void addCategoryType(String categoryTypeName, String categoryTypePropertyName, String elementTypeName, String elementTypePropertyName1, String elementTypePropertyName2, String elementTypePropertyName3, String elementTypePropertyName4) {
  28.         if (isUserValid()) {
  29.             ElementType elementType = new ElementType()
  30.                     .withName(elementTypeName)
  31.                     .withPropertyName1(elementTypePropertyName1)
  32.                     .withPropertyName2(elementTypePropertyName2)
  33.                     .withPropertyName3(elementTypePropertyName3)
  34.                     .withPropertyName4(elementTypePropertyName4);
  35.             CategoryType categoryType = new CategoryType()
  36.                     .withName(categoryTypeName)
  37.                     .withPropertyName(categoryTypePropertyName)
  38.                     .withElementTypeById(elementType);
  39.             categoryTypeDao.addCategoryType(categoryType);
  40.         } else {
  41.             throw new RuntimeException(new IllegalAccessException("Authentication failed"));
  42.         }
  43.     }
  44.  
  45.     private boolean isUserValid() {
  46.         MessageContext messageContext = webServiceContext.getMessageContext();
  47.         Map httpHeaders = (Map) messageContext.get(MessageContext.HTTP_REQUEST_HEADERS);
  48.         List userList = (List) httpHeaders.get(BindingProvider.USERNAME_PROPERTY);
  49.         List passwordList = (List) httpHeaders.get(BindingProvider.PASSWORD_PROPERTY);
  50.  
  51.         if (userList == null || passwordList == null) {
  52.             return false;
  53.         }
  54.  
  55.         if (userList.size() != 1 || passwordList.size() != 1) {
  56.             return false;
  57.         }
  58.  
  59.         String username = userList.get(0).toString();
  60.         String password = passwordList.get(0).toString();
  61.         System.out.println(username);
  62.         System.out.println(password);
  63.  
  64.         return ownerDao.areCredentialsValid(username, password);
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement